package com.example.zhaojianxu.signin.englishStudy.study.view

import android.graphics.Color
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.RadioGroup
import com.example.zhaojianxu.signin.R
import com.example.zhaojianxu.signin.common.bean.BaseFragment
import com.example.zhaojianxu.signin.englishStudy.study.model.StudyEntity
import kotlinx.android.synthetic.main.fragment_study.*

/**
 * create by @zhaojianxu on 2019/2/14
 */
class StudyFragment : BaseFragment() {

    var mView: View? = null
    var mListener: IStudyListener? = null
    var mResult = false
    private var mModel: StudyEntity? = null
    private var mPosition = 0


    override fun initView() {

        val radioGroup = mView!!.findViewById<RadioGroup>(R.id.view_study_radio_group)
        radioGroup!!.setOnCheckedChangeListener { group, checkedId ->
            view_study_radio_1.setTextColor(Color.BLACK)
            view_study_radio_2.setTextColor(Color.BLACK)
            view_study_radio_3.setTextColor(Color.BLACK)
            view_study_radio_4.setTextColor(Color.BLACK)
            when (checkedId) {
                R.id.view_study_radio_1 -> {
                    if (mModel?.items?.get(0)?.itemResult == mModel?.result){
                        mResult = true
                    }else{
                        mResult = false
                        view_study_radio_1.setTextColor(Color.RED)
                    }
                }
                R.id.view_study_radio_2 -> {
                    if (mModel?.items?.get(1)?.itemResult == mModel?.result){
                        mResult = true
                    }else{
                        mResult = false
                        view_study_radio_2.setTextColor(Color.RED)
                    }
                }
                R.id.view_study_radio_3 -> {
                    if (mModel?.items?.get(2)?.itemResult == mModel?.result){
                        mResult = true
                    }else{
                        mResult = false
                        view_study_radio_3.setTextColor(Color.RED)
                    }
                }
                R.id.view_study_radio_4 -> {
                    if (mModel?.items?.get(3)?.itemResult == mModel?.result){
                        mResult = true
                    }else{
                        mResult = false
                        view_study_radio_4.setTextColor(Color.RED)
                    }
                }
            }
        }
    }

    override fun initData() {
        mPosition = arguments?.getInt("position") ?: 0
        view_study_number.text = "第${mPosition+1}题"
        view_study_content.text = mModel?.content
        view_study_really.text = "${mModel?.result}"

        mListener = activity as? IStudyListener
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        mView = inflater.inflate(R.layout.fragment_study, container, false)

        return mView
    }

}